package cn.vconinfo.lims.delivery.service.impl;

import cn.vconinfo.base.utils.StringUtil;
import cn.vconinfo.lims.delivery.entity.*;
import cn.vconinfo.lims.delivery.mapper.DoctorMapper;
import cn.vconinfo.lims.delivery.mapper.GeneralManageMapper;
import cn.vconinfo.lims.delivery.mapper.InspectAppMapper;
import cn.vconinfo.lims.delivery.mapper.SpecimenCheckMapper;
import cn.vconinfo.lims.delivery.service.InspectAppService;
import cn.vconinfo.lims.delivery.utils.SystemConstant;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Description:
 * @Author: WHB
 * @Data: 2019-09-02 16:07
 */
@Service
public class InspectAppServiceImpl implements InspectAppService {

    @Resource
    private InspectAppMapper inspectAppMapper;

//    @Resource
//    private HospitalUploadService hospitalUploadService;

    @Resource
    private SpecimenCheckMapper specimenCheckMapper;

    @Resource
    private GeneralManageMapper generalManageMapper;

    @Resource
    private DoctorMapper doctorMapper;

//    @Resource
//    private ObjectMapper objectMapper;
//
//    @Resource
//    private PrintMapper printMapper;
//
//    @Resource
//    private ContentMapper contentMapper;
//
//    @Resource
//    private HospitalUploadMapper hospitalUploadMapper;

//    @Override
//    public TableResponseDTO getApplication(TableRequestDTO tableRequestDTO) throws Exception {
//        Date startDateSearchSql = tableRequestDTO.getJsonSearch().getDate("startDateSearch");
//        Date endDateSearchSql = tableRequestDTO.getJsonSearch().getDate("endDateSearch");
//        Long count = inspectAppMapper.getApplicationCount(startDateSearchSql, endDateSearchSql,
//                tableRequestDTO.getJsonSearch().getLong("officeSearch"), tableRequestDTO.getJsonSearch().getString("codeSearch"),
//                tableRequestDTO.getJsonSearch().getString("nameSearch"), tableRequestDTO.getKey());
//        List<InspectAppDTO> dtos = inspectAppMapper.getApplication(tableRequestDTO.getStart(count), tableRequestDTO.getPageSize()==null?12:tableRequestDTO.getPageSize(),
//                startDateSearchSql, endDateSearchSql,
//                tableRequestDTO.getJsonSearch().getLong("officeSearch"), tableRequestDTO.getJsonSearch().getString("codeSearch"),
//                tableRequestDTO.getJsonSearch().getString("nameSearch"), tableRequestDTO.getKey());
//        TableResponseDTO result = new TableResponseDTO(dtos,
//                new PaginationDTO(tableRequestDTO.getCurrent(), tableRequestDTO.getPageSize()==null?12:tableRequestDTO.getPageSize(), count, tableRequestDTO.getCurrentPage()));
//        result.setResponseCode(SystemConstant.OP_SUCCESS_LONG);
//        return result;
//    }

    /**
     * 手工单录入，列表调用了此处接口
     * @param tableRequestDTO
     * @return
     * @throws Exception
     */
//    @Override
//    public TableResponseDTO getRequest(TableRequestDTO tableRequestDTO) throws Exception {
//
//        // 查总数
//        Long count = inspectAppMapper.getRequestCount(tableRequestDTO.getJsonSearch().getLong("officeSearch"), tableRequestDTO.getJsonSearch().getString("codeSearch"),
//                tableRequestDTO.getJsonSearch().getString("nameSearch"), tableRequestDTO.getKey());
//
//        // 查列表
//        List<SpecimenCheckAndDocumentDTO> dtos = inspectAppMapper.getRequest1(tableRequestDTO.getStart(count), tableRequestDTO.getPageSize()==null?12:tableRequestDTO.getPageSize(),
//                tableRequestDTO.getJsonSearch().getLong("officeSearch"), tableRequestDTO.getJsonSearch().getString("codeSearch"),
//                tableRequestDTO.getJsonSearch().getString("nameSearch"), tableRequestDTO.getKey());
//
//        // 查询结果列表的检查单据  requestId
//        for (SpecimenCheckAndDocumentDTO dto : dtos) {
//            try {
//                dto.setProjectDocumentDTOList(inspectAppMapper.getAllRequestSpecimen((long)dto.getRequestId()));
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//
//
//        TableResponseDTO result = new TableResponseDTO(dtos,
//                new PaginationDTO(tableRequestDTO.getCurrent(), tableRequestDTO.getPageSize()==null?12:tableRequestDTO.getPageSize(), count, tableRequestDTO.getCurrentPage()));
//        result.setResponseCode(SystemConstant.OP_SUCCESS_LONG);
//        return result;
//    }

//    @Override
//    public TableResponseDTO getRequestList(TableRequestDTO tableRequestDTO) throws Exception{
//        Date startDateSearchSql = tableRequestDTO.getJsonSearch().getDate("startDateSearch");
//        Date endDateSearchSql = tableRequestDTO.getJsonSearch().getDate("endDateSearch");
//        Long count = inspectAppMapper.count4Request(tableRequestDTO.getJsonSearch().getLong("groupSearch"),startDateSearchSql,endDateSearchSql,
//                tableRequestDTO.getJsonSearch().getString("codeSearch"),tableRequestDTO.getJsonSearch().getLong("specimenIdSearch"),
//                tableRequestDTO.getHospitalId(),tableRequestDTO.getJsonSearch().getString("nameSearch"),tableRequestDTO.getJsonSearch().getLong("hospitalSearch")
//                );
//        List<SpecimenCheckDTO> dtos = inspectAppMapper.getRequestList(tableRequestDTO.getJsonSearch().getLong("groupSearch"),startDateSearchSql,endDateSearchSql,
//                tableRequestDTO.getJsonSearch().getString("codeSearch"),tableRequestDTO.getJsonSearch().getLong("specimenIdSearch"),
//                tableRequestDTO.getHospitalId(),tableRequestDTO.getJsonSearch().getString("nameSearch"),tableRequestDTO.getJsonSearch().getLong("hospitalSearch"),
//                tableRequestDTO.getStart(count), tableRequestDTO.getPageSize()==null?12:tableRequestDTO.getPageSize());
//        TableResponseDTO result = new TableResponseDTO(dtos,
//                new PaginationDTO(tableRequestDTO.getCurrent(), tableRequestDTO.getPageSize()==null?12:tableRequestDTO.getPageSize(), count, tableRequestDTO.getCurrentPage()));
//        result.setResponseCode(SystemConstant.OP_SUCCESS_LONG);
//        return result;
//    }



//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public TableResponseDTO addApplication(InspectAppDTO inspectAppDTO) throws Exception {
//        TableResponseDTO result = new TableResponseDTO();
//        DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
//        // 判断前端传来的时间值是否为空
//        Date applicationTime = inspectAppDTO.getApplicationTime().length() == 0 ? null : format.parse(inspectAppDTO.getApplicationTime());
//        Date samplingTime = inspectAppDTO.getSamplingTime() == null ? null : format.parse(inspectAppDTO.getSamplingTime());
//        Date enteringTime = inspectAppDTO.getEnteringTime() == null ? null : format.parse(inspectAppDTO.getEnteringTime());
//        Date confirmTime = inspectAppDTO.getConfirmTime() == null ? null : format.parse(inspectAppDTO.getConfirmTime());
//        if(inspectAppDTO.getPatientAge()==null){
//            inspectAppDTO.setPatientAge(0);
//        }
//        result.setResponseCode(inspectAppMapper.addApplication(inspectAppDTO.getPlaceholderCode(), inspectAppDTO.getDoorNum(),
//                inspectAppDTO.getPatientName(), inspectAppDTO.getPatientSex(), inspectAppDTO.getPatientAge(), inspectAppDTO.getPatientAgeType(),
//                inspectAppDTO.getPatientType(), inspectAppDTO.getPatientTag(), inspectAppDTO.getDepartmentId(), inspectAppDTO.getBedNum(),
//                inspectAppDTO.getDoctorId(), applicationTime, inspectAppDTO.getPatientOfficeId(),
//                samplingTime, inspectAppDTO.getEnteringManId(), enteringTime,
//                inspectAppDTO.getConfirmManId(), confirmTime, inspectAppDTO.getRemarks() ,inspectAppDTO.getDiagnosis()));
//        return result;
//    }


//    /**
//     * 手工单录入
//     */
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public TableResponseDTO addRequest(SpecimenCheckDTO specimenCheckDTO) throws Exception {
//        TableResponseDTO result = new TableResponseDTO();
//        DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
//        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
//        // 判断前端传来的时间值是否为空
////        Date applicationTime = inspectAppDTO.getApplicationTime().length() == 0 ? null : format.parse(inspectAppDTO.getApplicationTime());
////        Date samplingTime = inspectAppDTO.getSamplingTime() == null ? null : format.parse(inspectAppDTO.getSamplingTime());
////        Date enteringTime = inspectAppDTO.getEnteringTime() == null ? null : format.parse(inspectAppDTO.getEnteringTime());
////        Date confirmTime = inspectAppDTO.getConfirmTime() == null ? null : format.parse(inspectAppDTO.getConfirmTime());
//
//        if(specimenCheckDTO.getPatientAge()==null){
//            specimenCheckDTO.setPatientAge(0L);
//        }
//        Date date = new Date();
//        Date samplingTime = null;
//        if(specimenCheckDTO.getSamplingDate()!=null){
//            if(specimenCheckDTO.getSamplingDate().length()>10){
//                samplingTime = format.parse(specimenCheckDTO.getSamplingDate());
//            }else if(specimenCheckDTO.getSamplingDate().length()>0 && specimenCheckDTO.getSamplingDate().length()<=10){
//                samplingTime = format1.parse(specimenCheckDTO.getSamplingDate());
//            }else {
//                samplingTime = date;
//            }
//        }
//        specimenCheckDTO.setSamplingTime(samplingTime);
//
//        try {
//            //科室
//            Long deptId = specimenCheckMapper.getAppDeptIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDepartmentName());
//            if (null == deptId){
//                generalManageMapper.generalInsert(specimenCheckDTO.getApplicationDepartmentName(), specimenCheckDTO.getApplicationDepartmentName(),
//                        specimenCheckDTO.getHospitalId(), null, 3, null);
//                deptId = specimenCheckMapper.getAppDeptIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDepartmentName());
//            }
//            specimenCheckDTO.setApplicationDepartmentId(deptId);
//
//            //医生名称
//            if (specimenCheckDTO.getApplicationDoctorName() != null && !specimenCheckDTO.getApplicationDoctorName().equals("")) {
//                Long doctorId = specimenCheckMapper.getDocIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDoctorName(),
//                        specimenCheckDTO.getHospitalId()!=null?specimenCheckDTO.getHospitalId():213L);
//                if (doctorId == null){
//                    Long appDeptId = specimenCheckMapper.getAppDeptIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDepartmentName());
//                    doctorMapper.doctorAdd(specimenCheckDTO.getApplicationDoctorName(),
//                            specimenCheckDTO.getApplicationDoctorName(), null, specimenCheckDTO.getHospitalId(), appDeptId, 212L, null);
//                    doctorId = specimenCheckMapper.getDocIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDoctorName(),
//                            specimenCheckDTO.getHospitalId());
//                }
//                specimenCheckDTO.setApplicationDoctorId(doctorId);
//            }
//            specimenCheckDTO.setSamplingTime(samplingTime);
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//
//        result.setResponseCode(specimenCheckMapper.addRequest(specimenCheckDTO.getPlaceholderCode(),
//                specimenCheckDTO.getOutpatientId(), specimenCheckDTO.getPatientName(), specimenCheckDTO.getPatientSex(),
//                specimenCheckDTO.getPatientAge(), specimenCheckDTO.getPatientAgeType(), specimenCheckDTO.getPatientId(),
//                specimenCheckDTO.getBedNum(), specimenCheckDTO.getHospitalId(), specimenCheckDTO.getPatientType(),
//                specimenCheckDTO.getSpecimenType(), specimenCheckDTO.getTubeType(), specimenCheckDTO.getApplicationDepartmentId(),
//                specimenCheckDTO.getApplicationDoctorId(), specimenCheckDTO.getApplicationTime(), specimenCheckDTO.getSpecimenWindow(),
//                specimenCheckDTO.getSpecimenManId(), specimenCheckDTO.getSamplingTime(), specimenCheckDTO.getExecuteDepartmentId(),
//                specimenCheckDTO.getCheckManId(),  specimenCheckDTO.getPatientTag(), specimenCheckDTO.getDiagnosis(),
//                specimenCheckDTO.getPatientIdCardNum(), specimenCheckDTO.getRemarks(),1,specimenCheckDTO.getPatientTel(),
//                specimenCheckDTO.getDailyCode(),specimenCheckDTO.getInstitution(),specimenCheckDTO.getAddr()));
//        return result;
//    }

    /**
     * 手工单录入 并返回 自增id
     */
    @Transactional(rollbackFor = Exception.class)
    public TableResponseDTO addRequestAndReturnId(SpecimenCheckDTO specimenCheckDTO) throws Exception {
        TableResponseDTO result = new TableResponseDTO();
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
        // 判断前端传来的时间值是否为空
//        Date applicationTime = inspectAppDTO.getApplicationTime().length() == 0 ? null : format.parse(inspectAppDTO.getApplicationTime());
//        Date samplingTime = inspectAppDTO.getSamplingTime() == null ? null : format.parse(inspectAppDTO.getSamplingTime());
//        Date enteringTime = inspectAppDTO.getEnteringTime() == null ? null : format.parse(inspectAppDTO.getEnteringTime());
//        Date confirmTime = inspectAppDTO.getConfirmTime() == null ? null : format.parse(inspectAppDTO.getConfirmTime());

        if(specimenCheckDTO.getPatientAge()==null){
            specimenCheckDTO.setPatientAge(0L);
        }
        Date date = new Date();
        Date samplingTime = null;
        if(specimenCheckDTO.getSamplingDate()!=null){
            if(specimenCheckDTO.getSamplingDate().length()>10){
                samplingTime = format.parse(specimenCheckDTO.getSamplingDate());
            }else if(specimenCheckDTO.getSamplingDate().length()>0 && specimenCheckDTO.getSamplingDate().length()<=10){
                samplingTime = format1.parse(specimenCheckDTO.getSamplingDate());
            }else {
                samplingTime = date;
            }
        }
        specimenCheckDTO.setSamplingTime(samplingTime);

        try {
            //科室
            Long deptId = specimenCheckMapper.getAppDeptIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDepartmentName());
            if (null == deptId && StringUtils.isNotBlank(specimenCheckDTO.getApplicationDepartmentName())){
                generalManageMapper.generalInsert(specimenCheckDTO.getApplicationDepartmentName(), specimenCheckDTO.getApplicationDepartmentName(),
                        specimenCheckDTO.getHospitalId(), null, 3, null);
                deptId = specimenCheckMapper.getAppDeptIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDepartmentName());
            }
            specimenCheckDTO.setApplicationDepartmentId(deptId);

            //医生名称
            if (specimenCheckDTO.getApplicationDoctorName() != null && !specimenCheckDTO.getApplicationDoctorName().equals("")) {
                Long doctorId = specimenCheckMapper.getDocIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDoctorName(),
                        specimenCheckDTO.getHospitalId()!=null?specimenCheckDTO.getHospitalId():213L);
                if (doctorId == null){
                    Long appDeptId = specimenCheckMapper.getAppDeptIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDepartmentName());
                    doctorMapper.doctorAdd(specimenCheckDTO.getApplicationDoctorName(),
                            specimenCheckDTO.getApplicationDoctorName(), null, specimenCheckDTO.getHospitalId(), appDeptId, 212L, null);
                    doctorId = specimenCheckMapper.getDocIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDoctorName(),
                            specimenCheckDTO.getHospitalId());
                }
                specimenCheckDTO.setApplicationDoctorId(doctorId);
            }
            specimenCheckDTO.setSamplingTime(samplingTime);
        }catch (Exception e){
            e.printStackTrace();
        }

        result.setResponseCode(specimenCheckMapper.addRequestAndReturnId(specimenCheckDTO));
        result.setOpResult(specimenCheckDTO.getRequestId() + "");
        return result;
    }

    /**
     * 手工单录入  集成了单据的添加
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public TableResponseDTO addRequestAndAddProjectDocuments(SpecimenCheckAndProjectDocumentIdsDTO specimenCheckAndProjectDocumentIdsDTO) throws Exception {
        // 基本信息（不包含单据）
        TableResponseDTO tableResponseDTO = addRequestAndReturnId(specimenCheckAndProjectDocumentIdsDTO);

        if (tableResponseDTO.getResponseCode() == 1L) {
            // 工单基础信息添加成功 添加绑定的单据
            if (
                    !CollectionUtils.isEmpty(specimenCheckAndProjectDocumentIdsDTO.getProjectDocumentIds())
            ) {
                // 判断requestId是否正常生成
                if (StringUtils.isEmpty(tableResponseDTO.getOpResult())) {
                    // requestId没有正常生成
                    tableResponseDTO.setOpResult("requestId没有正常生成");
                } else {
                    // 添加绑定的单据
                    tableResponseDTO = addRequestSpecimens(specimenCheckAndProjectDocumentIdsDTO.getProjectDocumentIds(), tableResponseDTO.getOpResult());
                }
            }
        }

        return tableResponseDTO;
    }


//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public TableResponseDTO editRequest(SpecimenCheckDTO specimenCheckDTO) throws Exception {
//        TableResponseDTO result = new TableResponseDTO();
//        DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
//        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
//        // 判断前端传来的时间值是否为空
////        Date applicationTime = inspectAppDTO.getApplicationTime().length() == 0 ? null : format.parse(inspectAppDTO.getApplicationTime());
////        Date samplingTime = inspectAppDTO.getSamplingTime() == null ? null : format.parse(inspectAppDTO.getSamplingTime());
////        Date enteringTime = inspectAppDTO.getEnteringTime() == null ? null : format.parse(inspectAppDTO.getEnteringTime());
////        Date confirmTime = inspectAppDTO.getConfirmTime() == null ? null : format.parse(inspectAppDTO.getConfirmTime());
//
//        if(specimenCheckDTO.getPatientAge()==null){
//            specimenCheckDTO.setPatientAge(0L);
//        }
//        Date date = new Date();
//        Date samplingTime = null;
//        if(specimenCheckDTO.getSamplingDate()!=null){
//            if(specimenCheckDTO.getSamplingDate().length()>10){
//                samplingTime = format.parse(specimenCheckDTO.getSamplingDate());
//            }else if(specimenCheckDTO.getSamplingDate().length()>0 && specimenCheckDTO.getSamplingDate().length()<=10){
//                samplingTime = format1.parse(specimenCheckDTO.getSamplingDate());
//            }else {
//                samplingTime = date;
//            }
//        }
//        specimenCheckDTO.setSamplingTime(samplingTime);
//
//        try{
//            //科室
//            Long deptId = specimenCheckMapper.getAppDeptIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDepartmentName());
//            if (null == deptId){
//                generalManageMapper.generalInsert(specimenCheckDTO.getApplicationDepartmentName(), specimenCheckDTO.getApplicationDepartmentName(),
//                        specimenCheckDTO.getHospitalId(), null, 3, null);
//                deptId = specimenCheckMapper.getAppDeptIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDepartmentName());
//            }
//            specimenCheckDTO.setApplicationDepartmentId(deptId);
//
//            //医生名称
//            if (specimenCheckDTO.getApplicationDoctorName() != null && !specimenCheckDTO.getApplicationDoctorName().equals("")) {
//                Long doctorId = specimenCheckMapper.getDocIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDoctorName(),
//                        specimenCheckDTO.getHospitalId()!=null?specimenCheckDTO.getHospitalId():213L);
//                if (doctorId == null){
//                    Long appDeptId = specimenCheckMapper.getAppDeptIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDepartmentName());
//                    doctorMapper.doctorAdd(specimenCheckDTO.getApplicationDoctorName(),
//                            specimenCheckDTO.getApplicationDoctorName(), null, specimenCheckDTO.getHospitalId(), appDeptId, 212L, null);
//                    doctorId = specimenCheckMapper.getDocIdForSpecimenCheckInsert(specimenCheckDTO.getApplicationDoctorName(),
//                            specimenCheckDTO.getHospitalId());
//                }
//                specimenCheckDTO.setApplicationDoctorId(doctorId);
//            }
//            specimenCheckDTO.setSamplingTime(samplingTime);
//        }catch (Exception e){
//
//        }
//
//        result.setResponseCode(specimenCheckMapper.editRequest(specimenCheckDTO.getPlaceholderCode(),
//                specimenCheckDTO.getOutpatientId(), specimenCheckDTO.getPatientName(), specimenCheckDTO.getPatientSex(),
//                specimenCheckDTO.getPatientAge(), specimenCheckDTO.getPatientAgeType(), specimenCheckDTO.getPatientId(),
//                specimenCheckDTO.getBedNum(), specimenCheckDTO.getHospitalId(), specimenCheckDTO.getPatientType(),
//                specimenCheckDTO.getSpecimenType(), specimenCheckDTO.getTubeType(), specimenCheckDTO.getApplicationDepartmentId(),
//                specimenCheckDTO.getApplicationDoctorId(), specimenCheckDTO.getApplicationTime(), specimenCheckDTO.getSpecimenWindow(),
//                specimenCheckDTO.getSpecimenManId(), specimenCheckDTO.getSamplingTime(), specimenCheckDTO.getExecuteDepartmentId(),
//                specimenCheckDTO.getCheckManId(),  specimenCheckDTO.getPatientTag(), specimenCheckDTO.getDiagnosis(),
//                specimenCheckDTO.getPatientIdCardNum(), specimenCheckDTO.getRemarks(),specimenCheckDTO.getRequestId(),
//                specimenCheckDTO.getPatientTel(),specimenCheckDTO.getBirthDate()));
//
//        return result;
//    }

//    /**
//     * 编辑 集成了检验单据的修改
//     * @param specimenCheckAndProjectDocumentIdsDTO
//     * @return
//     */
//    public TableResponseDTO editAndProjectDocumentRequest(SpecimenCheckAndProjectDocumentIdsDTO specimenCheckAndProjectDocumentIdsDTO) throws Exception {
//        TableResponseDTO tableResponseDTO = editRequest(specimenCheckAndProjectDocumentIdsDTO);
//        if (tableResponseDTO.getResponseCode() == 0) {
//            // 修改失败
//            return tableResponseDTO;
//        }
//
//        // 修改相关的检验单据
//        tableResponseDTO = addRequestSpecimens(specimenCheckAndProjectDocumentIdsDTO.getProjectDocumentIds(), specimenCheckAndProjectDocumentIdsDTO.getRequestId() + "");
//
//        return tableResponseDTO;
//    }

//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public TableResponseDTO editApplication(InspectAppDTO inspectAppDTO) throws Exception {
//        TableResponseDTO result = new TableResponseDTO();
//        DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
//        // 判断前端传来的时间值是否为空
//        Date applicationTime = inspectAppDTO.getApplicationTime().length() == 0 ? null : format.parse(inspectAppDTO.getApplicationTime());
//        Date samplingTime = inspectAppDTO.getSamplingTime() == null ? null : format.parse(inspectAppDTO.getSamplingTime());
//        Date enteringTime = inspectAppDTO.getEnteringTime() == null ? null : format.parse(inspectAppDTO.getEnteringTime());
//        Date confirmTime = inspectAppDTO.getConfirmTime() == null ? null : format.parse(inspectAppDTO.getConfirmTime());
//        result.setResponseCode(inspectAppMapper.editApplication(inspectAppDTO.getPlaceholderCode(), inspectAppDTO.getDoorNum(),
//                inspectAppDTO.getPatientName(), inspectAppDTO.getPatientSex(), inspectAppDTO.getPatientAge(), inspectAppDTO.getPatientAgeType(),
//                inspectAppDTO.getPatientType(), inspectAppDTO.getPatientTag(), inspectAppDTO.getDepartmentId(), inspectAppDTO.getBedNum(),
//                inspectAppDTO.getDoctorId(), applicationTime, inspectAppDTO.getPatientOfficeId(), samplingTime, inspectAppDTO.getEnteringManId(),
//                enteringTime, inspectAppDTO.getConfirmManId(), confirmTime, inspectAppDTO.getRemarks() ,inspectAppDTO.getDiagnosis(),
//                inspectAppDTO.getApplicationId()));
//        return result;
//    }

//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public TableResponseDTO removeApplication(InspectAppDTO inspectAppDTO) throws Exception {
//        TableResponseDTO result = new TableResponseDTO();
//        result.setResponseCode(inspectAppMapper.removeApplication(inspectAppDTO.getApplicationId()));
//        return result;
//    }

//    @Override
//    public TableResponseDTO getSpecimen(TableRequestDTO tableRequestDTO) throws Exception {
//        if(tableRequestDTO.getKey() == null) {
//            return new TableResponseDTO(null, new PaginationDTO(tableRequestDTO.getCurrent(),
//                    tableRequestDTO.getPageSize(), 0L, tableRequestDTO.getCurrentPage())
//            );
//        }
//        Long count = inspectAppMapper.getSpecimenCount(tableRequestDTO.getKey());
//        List<ProjectDocumentDTO> dtos = inspectAppMapper.getSpecimen(tableRequestDTO.getStart(count),
//                tableRequestDTO.getPageSize()==null?12:tableRequestDTO.getPageSize(), tableRequestDTO.getKey());
//        for(ProjectDocumentDTO projectDocumentDTO: dtos) {
//            projectDocumentDTO.setKey(projectDocumentDTO.getProjectDocumentId());
//        }
//        TableResponseDTO result = new TableResponseDTO(dtos,
//                new PaginationDTO(tableRequestDTO.getCurrent(), tableRequestDTO.getPageSize()==null?12:tableRequestDTO.getPageSize(), count, tableRequestDTO.getCurrentPage()));
//        result.setResponseCode(SystemConstant.OP_SUCCESS_LONG);
//        return result;
//    }

//    /**
//     * 查询检验单据
//     * @param tableRequestDTO
//     * @return
//     * @throws Exception
//     */
//    @Override
//    public TableResponseDTO getRequsetSpecimen(TableRequestDTO tableRequestDTO) throws Exception {
//        if(tableRequestDTO.getKey() == null) {
//            return new TableResponseDTO(null, new PaginationDTO(tableRequestDTO.getCurrent(),
//                    tableRequestDTO.getPageSize(), 0L, tableRequestDTO.getCurrentPage())
//            );
//        }
//        Long count = inspectAppMapper.getRequestSpecimenCount(tableRequestDTO.getKey());
//        List<ProjectDocumentDTO> dtos = inspectAppMapper.getRequestSpecimen(tableRequestDTO.getStart(count),
//                tableRequestDTO.getPageSize(), tableRequestDTO.getKey());
//        for(ProjectDocumentDTO projectDocumentDTO: dtos) {
//            projectDocumentDTO.setKey(projectDocumentDTO.getProjectDocumentId());
//        }
//        TableResponseDTO result = new TableResponseDTO(dtos,
//                new PaginationDTO(tableRequestDTO.getCurrent(), tableRequestDTO.getPageSize()==null?12:tableRequestDTO.getPageSize(), count, tableRequestDTO.getCurrentPage()));
//        result.setResponseCode(SystemConstant.OP_SUCCESS_LONG);
//        return result;
//    }

//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public TableResponseDTO addSpecimen(Long projectDocumentId, Long applicationId) throws Exception {
//
//        TableResponseDTO result = new TableResponseDTO();
//        List<ProjectDocumentDTO> list = inspectAppMapper.getAllSpecimen(applicationId);
//        for(ProjectDocumentDTO projectDocumentDTO: list) {
//            if(projectDocumentDTO.getProjectDocumentId().equals(projectDocumentId)) {
//                result.setResponseCode(0L);
//                return result;
//            }else if(projectDocumentDTO.getProjectDocumentId()==25){
//                 if(projectDocumentId==19){
//                     result.setResponseCode(0L);
//                     return result;
//                 }
//            }else if(projectDocumentDTO.getProjectDocumentId()==19){
//                if(projectDocumentId==25){
//                    result.setResponseCode(0L);
//                    return result;
//                }
//            }
//        }
//        result.setResponseCode(inspectAppMapper.addSpecimen(projectDocumentId, applicationId));
//        return result;
//    }

//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public TableResponseDTO addRequestSpecimen(Long projectDocumentId, Long requestId) throws Exception {
//
//        TableResponseDTO result = new TableResponseDTO();
//        // 查询已经存在的单据
//        List<ProjectDocumentDTO> list = inspectAppMapper.getAllRequsetSpecimen(requestId);
//        for(ProjectDocumentDTO projectDocumentDTO: list) {
//            if(projectDocumentDTO.getProjectDocumentId().equals(projectDocumentId)) {
//                result.setResponseCode(0L);
//                return result;
//            }else if(projectDocumentDTO.getProjectDocumentId()==25){
//                 if(projectDocumentId==19){
//                     result.setResponseCode(0L);
//                     return result;
//                 }
//            }else if(projectDocumentDTO.getProjectDocumentId()==19){
//                if(projectDocumentId==25){
//                    result.setResponseCode(0L);
//                    return result;
//                }
//            }
//        }
//        result.setResponseCode(inspectAppMapper.addRequestSpecimen(projectDocumentId, requestId));
//        return result;
//    }




    /**
     * 添加或删除多个单据
     * @param projectDocumentIds 多个单据主键
     * @param requestId
     * @return
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public TableResponseDTO addRequestSpecimens(List<String> projectDocumentIds, String requestId) throws Exception {
        TableResponseDTO tableResponseDTO = new TableResponseDTO();
        tableResponseDTO.setResponseCode(SystemConstant.OP_SUCCESS_LONG);



        if (StringUtil.isEmpty(requestId)) {
            tableResponseDTO.setResponseCode(0L);
            tableResponseDTO.setOpResult("requestId为空");
        }


        // 查询已经存在的单据
        List<ProjectDocumentDTO> list = inspectAppMapper.getAllRequsetSpecimen(Long.parseLong(requestId));

        // 判断是否有单据项目id 如果没有则删除已经关联的数据后返回即可   start
        if (projectDocumentIds == null || projectDocumentIds.size() < 1) {
            // 没有单据项目的id  判断是否有老的需要删除   start
            if (list != null && list.size() > 0) {
                // 删除老的数据
                for (ProjectDocumentDTO projectDocumentDTO : list) {
                    inspectAppMapper.removeSpecimen(projectDocumentDTO.getApplicationLinkId());
                }
            }

            // 没有单据项目的id  判断是否有老的需要删除   end
            return tableResponseDTO;
        }
        // 判断是否有单据项目id 如果没有则删除已经关联的数据后返回即可   end


        // 维护当前数据库中的id 用于插入前的的验证
        Map<String, String> nowHaveProjectDocumentId = new HashMap<>();

        // 当前要添加的id
        List<String> now = new ArrayList<>();
        // 已经存在的id projectDocumentId
        List<String> exist = new ArrayList<>();





        for (String projectDocumentId : projectDocumentIds) {
            if (StringUtils.isNotEmpty(projectDocumentId)) {
                now.add(projectDocumentId);
            }
        }


        for (ProjectDocumentDTO projectDocumentDTO : list) {
            if (projectDocumentDTO.getProjectDocumentId() != null) {
                String nowProjectDocumentId = projectDocumentDTO.getProjectDocumentId().toString();
                exist.add(nowProjectDocumentId);
                nowHaveProjectDocumentId.put(nowProjectDocumentId, nowProjectDocumentId);
            }
        }
        /*
        因为前端为多选下拉框，添加删除的操作都有可能存在 所有这边解析出本次要添加的数据（原来没有这次有） 和 要删除的数据（原来有这次没有） start
         */

        // 需要删除的id
        List<Map<String, Object>> needRemoveApplicationLinkIdAndProjectDocumentId = getNeedRemoveApplicationLinkId(list, now);
        // 需要添加的id
        List<String> needAddProjectDocumentId = getNeedAddProjectDocumentId(exist, now);




        // 开始删除
        for (Map<String, Object> nowNeedRemoveApplicationLinkIdAndProjectDocumentId : needRemoveApplicationLinkIdAndProjectDocumentId) {
            inspectAppMapper.removeSpecimen(Long.parseLong(nowNeedRemoveApplicationLinkIdAndProjectDocumentId.get("needRemoveApplicationLinkId").toString()));
            nowHaveProjectDocumentId.remove(nowNeedRemoveApplicationLinkIdAndProjectDocumentId.get("projectDocumentId").toString());
        }

        // 开始添加    TODO: 2021/7/20 当前项目中只有 19  添加此段逻辑是为了 和之前的逻辑保持统一 以防止修改的时候有没有注意到的地方
        for (String nowNeedAddProjectDocumentId : needAddProjectDocumentId) {
            // 添加前参考之前逻辑进而二次验证 （ projectDocumentId 19 和 25 不需重复添加 ） start
            if (
                    nowNeedAddProjectDocumentId.equals("19") || nowNeedAddProjectDocumentId.equals("25")
            ) {
                if (nowHaveProjectDocumentId.containsKey("19") || nowHaveProjectDocumentId.containsKey("25")) {
                    // 当添加 19 或 25 的时候 项目中已经存在 19 或 25 了 所以本次不进行添加
                    continue;
                }
            }

            // 添加前参考之前逻辑进而二次验证 （ projectDocumentId 19 和 25 不需重复添加 ） end

            inspectAppMapper.addRequestSpecimen(Long.parseLong(nowNeedAddProjectDocumentId), Long.parseLong(requestId));
            nowHaveProjectDocumentId.put(nowNeedAddProjectDocumentId, nowNeedAddProjectDocumentId);
        }

        /*
        因为前端为多选下拉框，添加删除的操作都有可能存在 所有这边解析出本次要添加的数据（原来没有这次有） 和 要删除的数据（原来有这次没有） end
        */

        return tableResponseDTO;
    }


    /**
     * 获得需要删除的单据
     * @param exist 已经存在的单据
     * @param now 本次需要添加的单据
     * @return List<Map<String, Object>>
     *    map中的数据为 {
     *     needRemoveApplicationLinkId 需要删除的id
     *     projectDocumentId 单据的id
     * }
     *
     */
    public List<Map<String, Object>> getNeedRemoveApplicationLinkId(List<ProjectDocumentDTO> exist,List<String> now) {
        List<Map<String, Object>> needRemoveApplicationLinkId = new ArrayList<>();
        // now 中 存在 exist 中不存在的数据
        if (
                exist != null && !(exist.isEmpty())
        ) {
            for (ProjectDocumentDTO projectDocumentDTO : exist) {
                // 当前是否需要添加到返回list中  0 不需要删除  1 需要删除
                int isNeedRemove = 1;
                for (String nowId : now) {
                    if (projectDocumentDTO.getProjectDocumentId() != null) {
                        if (nowId.equals(projectDocumentDTO.getProjectDocumentId().toString())) {
                            isNeedRemove = 0;
                        }
                    }
                }

                if (
                        isNeedRemove == 1 && projectDocumentDTO.getApplicationId() != null
                ) {
                    Map<String, Object> nowData = new HashMap<>();
                    nowData.put("needRemoveApplicationLinkId", projectDocumentDTO.getApplicationLinkId().toString());
                    nowData.put("projectDocumentId", projectDocumentDTO.getProjectDocumentId().toString());
                    needRemoveApplicationLinkId.add(nowData);
                }
            }
        }

        return needRemoveApplicationLinkId;
    }

    /**
     * 需要添加的单据
     * @param exist 已经存在的单据
     * @param now 本次需要添加的单据
     * @return
     */
    public List<String> getNeedAddProjectDocumentId(List<String> exist,List<String> now) {
        List<String> needAddProjectDocumentId = new ArrayList<>();

        for (String nowId : now) {
            // 当前是否需要添加到返回list中  0 不需要添加  1 需要添加
            int isNeed = 1;
            for (String nowExistId : exist) {
                if (nowExistId.equals(nowId)) {
                    isNeed = 0;
                }
            }
            if (isNeed == 1) {
                needAddProjectDocumentId.add(nowId);
            }
        }

        return needAddProjectDocumentId;
    }





//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public TableResponseDTO removeSpecimen(Long applicationLinkId) throws Exception {
//        TableResponseDTO result = new TableResponseDTO();
//        result.setResponseCode(inspectAppMapper.removeSpecimen(applicationLinkId));
//        return result;
//    }

//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public TableResponseDTO addSpecimenByGroup(Long projectPackageId, Long applicationId) throws Exception {
//        TableResponseDTO result = new TableResponseDTO();
//        List<Long> list = inspectAppMapper.getDocumentIdInSpecimen(applicationId);
//        List<Long> documentList = inspectAppMapper.getDocumentListByPackageId(projectPackageId);
//        int flag = 0;
//        for(Long documentId: documentList) {
//            if(!list.contains(documentId)) {
//                result.setResponseCode(inspectAppMapper.addSpecimen(documentId, applicationId));
//                flag = 1;
//            }
//        }
//        if(flag == 0) {
//            result.setResponseCode(0L);
//        }
//        return result;
//    }

//    @Override
//    public TableResponseDTO getSpecimenUnregister(TableRequestDTO tableRequestDTO) throws Exception {
//        String search = tableRequestDTO.getSearch();
//        if(null == search){
//            search = "";
//        }
//        Long count = inspectAppMapper.count4SpecimenUnregister(search,tableRequestDTO.getKey());
//        List<SpecimenRegisterDTO> list = inspectAppMapper.getSpecimenUnregister(tableRequestDTO.getPageSize(),
//                tableRequestDTO.getStart(count), search,tableRequestDTO.getKey());
//        TableResponseDTO result = new TableResponseDTO(list, new PaginationDTO(tableRequestDTO.getCurrent(),
//                tableRequestDTO.getPageSize(), count,tableRequestDTO.getCurrentPage()));
//        return result;
//    }

//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public Boolean registerSpecimen(List<SpecimenRegisterDTO> list) throws Exception {
//        for(SpecimenRegisterDTO value: list) {
//            // 当年龄类型为空时默认为岁 typeInfoId 为38
//            if(null == value.getPatientAgeType()) value.setPatientAgeType(38);
//            if(null == value.getPatientSex()) value.setPatientSex(33);
//            if(null == value.getPatientName()) value.setPatientName(" ");
//            if(null == value.getPatientAge()) value.setPatientAge(18);
//            Boolean flag = inspectAppMapper.registerSpecimen(value);
//            Boolean flag2 = inspectAppMapper.setRegister(value.getApplicationLinkId());
//            if(!flag || !flag2) {
//                return false;
//            }
//        }
//        return true;
//    }

//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public TableResponseDTO registerSpecimenByList(List<Long> list) throws Exception {
//        TableResponseDTO tableResponseDTO = new TableResponseDTO();
//        List<SpecimenRegisterDTO> registerDTOS = new ArrayList<>();
//        try {
//            if(list.size()>0){
//                LinkedHashSet<Long> hashSet = new LinkedHashSet<>(list);
//                list = new ArrayList<>(hashSet);
//                for(int i =0;i<list.size();i++){
//                    List<SpecimenRegisterDTO> specimenRegisterDTOList = inspectAppMapper.getRequestListByRequestId(list.get(i));
//                    if(specimenRegisterDTOList.size()>0){
//                        for(int k= 0;k<specimenRegisterDTOList.size();k++){
//                            SpecimenRegisterDTO specimenRegisterDTO = specimenRegisterDTOList.get(k);
//                            if(specimenRegisterDTO.getPlaceholderCode()==null||
//                                    (!"".equals(specimenRegisterDTO.getPlaceholderCode().trim())&&specimenRegisterDTO.getPlaceholderCode().trim()!=null)){
//                                long count = inspectAppMapper.checkHasPlaceCode(specimenRegisterDTO.getHospitalId(),
//                                        specimenRegisterDTO.getPlaceholderCode(),specimenRegisterDTO.getProjectDocumentId());
//                                if(count>0){
//                                    registerDTOS.add(specimenRegisterDTO);
//                                }else {
//                                    // 当年龄类型为空时默认为岁 typeInfoId 为38
//                                    if(null == specimenRegisterDTO.getPatientAgeType()) specimenRegisterDTO.setPatientAgeType(38);
//                                    if(null == specimenRegisterDTO.getPatientSex()) specimenRegisterDTO.setPatientSex(33);
//                                    if(null == specimenRegisterDTO.getPatientName()) specimenRegisterDTO.setPatientName(" ");
//                                    if(null == specimenRegisterDTO.getPatientAge()) specimenRegisterDTO.setPatientAge(18);
//                                    if(null == specimenRegisterDTO.getSamplingTime()){
//                                        DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//                                        Date nowTime = new Date();
//                                        specimenRegisterDTO.setSamplingTime(format.format(nowTime));
//                                    }
//                                    if(null==specimenRegisterDTO.getPatientType()){
//                                        specimenRegisterDTO.setPatientType(0);
//                                    }
//                                    Boolean flag = inspectAppMapper.registerSpecimen(specimenRegisterDTO);
//                                    Boolean flag2 = inspectAppMapper.setRegister(specimenRegisterDTO.getApplicationLinkId());
//                                    registerDTOS.add(specimenRegisterDTO);
//                                }
//                            }else {
//                                specimenRegisterDTO.setPlaceholderCode(null);
//                                // 当年龄类型为空时默认为岁 typeInfoId 为38
//                                if(null == specimenRegisterDTO.getPatientAgeType()) specimenRegisterDTO.setPatientAgeType(38);
//                                if(null == specimenRegisterDTO.getPatientSex()) specimenRegisterDTO.setPatientSex(33);
//                                if(null == specimenRegisterDTO.getPatientName()) specimenRegisterDTO.setPatientName(" ");
//                                if(null == specimenRegisterDTO.getPatientAge()) specimenRegisterDTO.setPatientAge(18);
//                                if(null == specimenRegisterDTO.getSamplingTime()){
//                                    DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//                                    Date nowTime = new Date();
//                                    specimenRegisterDTO.setSamplingTime(format.format(nowTime));
//                                }
//                                if(null==specimenRegisterDTO.getPatientType()){
//                                    specimenRegisterDTO.setPatientType(0);
//                                }
//
//                                //查找simpleId的重复情况，如果不存在重复则添加数据（count=0），如果重复则不进行添加
//                                long count = inspectAppMapper.checkHasSampleID(specimenRegisterDTO.getApplicationLinkId());
//                                if(count==0){
//                                    Boolean flag = inspectAppMapper.registerSpecimen(specimenRegisterDTO);
//                                    Boolean flag2 = inspectAppMapper.setRegister(specimenRegisterDTO.getApplicationLinkId());
//                                    System.out.println("insert data");
//                                }else {
//                                    System.out.println(specimenRegisterDTO.toString());
//                                    registerDTOS.add(specimenRegisterDTO);
//                                }
//                                registerDTOS.add(specimenRegisterDTO);
//
//                            }
//                        }
//                    }
//                }
//            }
//            tableResponseDTO.setList(registerDTOS);
//            tableResponseDTO.setResponseCode(SystemConstant.OP_SUCCESS_LONG);
//        }catch (Exception e){
//            tableResponseDTO.setList(registerDTOS);
//            tableResponseDTO.setResponseCode(SystemConstant.OP_FAILURE_LONG);
//        }
//        return tableResponseDTO;
//    }

//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public TableResponseDTO registerSpecimenByCode(TableRequestDTO tableRequestDTO) throws Exception {
//        TableResponseDTO tableResponseDTO = new TableResponseDTO();
//        List<SpecimenRegisterDTO> registerDTOS = new ArrayList<>();
//        List<SpecimenRegisterDTO> returnDto = new ArrayList<>();
//        try{
//            registerDTOS = inspectAppMapper.getRequestListByPlacecode(tableRequestDTO.getHospitalId(),tableRequestDTO.getPlacecode());
//            if(registerDTOS.size()>0){
//                for(int i=0;i<registerDTOS.size();i++){
//                    SpecimenRegisterDTO specimenRegisterDTO = registerDTOS.get(i);
//                    long count = inspectAppMapper.checkHasPlaceCode(specimenRegisterDTO.getHospitalId(),
//                            specimenRegisterDTO.getPlaceholderCode(),specimenRegisterDTO.getProjectDocumentId());
//                    if(count>0){
//                        returnDto.add(specimenRegisterDTO);
//                    }else {
//                        // 当年龄类型为空时默认为岁 typeInfoId 为38
//                        if(null == specimenRegisterDTO.getPatientAgeType()) specimenRegisterDTO.setPatientAgeType(38);
//                        if(null == specimenRegisterDTO.getPatientSex()) specimenRegisterDTO.setPatientSex(33);
//                        if(null == specimenRegisterDTO.getPatientName()) specimenRegisterDTO.setPatientName(" ");
//                        if(null == specimenRegisterDTO.getPatientAge()) specimenRegisterDTO.setPatientAge(18);
//                        if(null == specimenRegisterDTO.getSamplingTime()){
//                            DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//                            Date nowTime = new Date();
//                            specimenRegisterDTO.setSamplingTime(format.format(nowTime));
//                        }
//                        if(null==specimenRegisterDTO.getPatientType()){
//                            specimenRegisterDTO.setPatientType(0);
//                        }
//                        Boolean flag = inspectAppMapper.registerSpecimen(specimenRegisterDTO);
//                        Boolean flag2 = inspectAppMapper.setRegister(specimenRegisterDTO.getApplicationLinkId());
//                        returnDto.add(specimenRegisterDTO);
//                    }
//                    tableResponseDTO.setList(returnDto);
//                    tableResponseDTO.setResponseCode(SystemConstant.OP_SUCCESS_LONG);
//                }
//            }
//        }catch (Exception e){
//            tableResponseDTO.setList(returnDto);
//            tableResponseDTO.setResponseCode(SystemConstant.OP_FAILURE_LONG);
//        }
//        return tableResponseDTO;
//    }

//    /**
//     * 标本审核列表
//     */
//    @Override
//    public TableResponseDTO getSpecimenRegister(SpecimenTableRequestDTO tableRequestDTO) throws Exception {
//
//        Date startDateSearchSql = tableRequestDTO.getJsonSearch().getDate("startDateSearch");
//        Date endDateSearchSql = tableRequestDTO.getJsonSearch().getDate("endDateSearch");
//
//        Long count = inspectAppMapper.count4SpecimenRegister(tableRequestDTO.getJsonSearch().getLong("deviceGroupSearch"),
//                startDateSearchSql, endDateSearchSql, tableRequestDTO.getJsonSearch().getString("codeSearch"),
//                tableRequestDTO.getJsonSearch().getLong("specimenIdSearch"), tableRequestDTO.getJsonSearch().getLong("statusSearch"),
//                tableRequestDTO.getKey(),tableRequestDTO.getJsonSearch().getString("nameSearch"),tableRequestDTO.getJsonSearch().getLong("hospitalId"),
//                tableRequestDTO.getJsonSearch().getLong("sendLogo"),tableRequestDTO.getJsonSearch().getLong("projectDocumentId"),
//                tableRequestDTO.getJsonSearch().getString("dailyCode"));
//
//        List<SpecimenRegisterDTO> list = inspectAppMapper.getSpecimenRegister(tableRequestDTO.getStart(count), tableRequestDTO.getPageSize()==null?12:tableRequestDTO.getPageSize(),
//                tableRequestDTO.getJsonSearch().getLong("deviceGroupSearch"), startDateSearchSql, endDateSearchSql,
//                tableRequestDTO.getJsonSearch().getString("codeSearch"), tableRequestDTO.getJsonSearch().getLong("specimenIdSearch"),
//                tableRequestDTO.getJsonSearch().getLong("statusSearch"), tableRequestDTO.getKey(),tableRequestDTO.getJsonSearch().getString("nameSearch"),tableRequestDTO.getJsonSearch().getLong("hospitalId"),
//                tableRequestDTO.getJsonSearch().getLong("sendLogo"),tableRequestDTO.getJsonSearch().getLong("projectDocumentId"),
//                tableRequestDTO.getJsonSearch().getString("dailyCode"));
//
//        TableResponseDTO result = new TableResponseDTO(list, new PaginationDTO(tableRequestDTO.getCurrent(),
//                tableRequestDTO.getPageSize()==null?12:tableRequestDTO.getPageSize(),count,tableRequestDTO.getCurrentPage()));
//
//        return result;
//    }

//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public Boolean registerSpecimenDelete(SpecimenRegisterDTO specimenRegisterDTO) throws Exception {
//        Boolean flag = inspectAppMapper.registerSpecimenDelete(specimenRegisterDTO.getSpecimenRegisterId());
////        Boolean flag2 = inspectAppMapper.setUnregister(specimenRegisterDTO.getSpecimenExtraId());
//        if (!flag
////                || !flag2
//        ) {
//            return false;
//        }
//        return true;
//    }

//    /**
//     * 标本审核 批量删除
//     */
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public TableResponseDTO registerSpecimenDeleteMore(TableRequestDTO tableRequestDTO) throws Exception {
//        TableResponseDTO returnDto = new TableResponseDTO();
//
//        List<Long> specimenRegisterIdS = tableRequestDTO.getArray();
//
//        if (specimenRegisterIdS == null || specimenRegisterIdS.isEmpty()) {
//
//            // 必填参数为空
//            returnDto.setList(SystemConstant.OP_FAILURE_OBJ);
//            returnDto.setResponseCode(SystemConstant.OP_FAILURE_LONG);
//
//        } else {
//
//            for (Long specimenRegisterId : specimenRegisterIdS) {
//                inspectAppMapper.registerSpecimenDelete(specimenRegisterId);
//            }
//
//            returnDto.setList(SystemConstant.OP_SUCCESS_OBJ);
//            returnDto.setResponseCode(SystemConstant.OP_SUCCESS_LONG);
//        }
//
//        return returnDto;
//    }


//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public Boolean registerSpecimenEdit(SpecimenRegisterDTO specimenRegisterDTO) throws Exception {
//        Boolean flag = inspectAppMapper.registerSpecimenEdit(specimenRegisterDTO);
//        if(!flag) {
//            return false;
//        }
//        return true;
//    }

//    /**
//     * 微信小程序编辑服务
//     * @param specimenRegisterDTO
//     * @return
//     * @throws Exception
//     */
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public Boolean wxRegisterSpecimenEdit(SpecimenRegisterDTO specimenRegisterDTO) throws Exception {
//
//        if(specimenRegisterDTO.getDepartmentName()!=null){
//            Long deptId = specimenCheckMapper.getAppDeptIdForSpecimenCheckInsert(specimenRegisterDTO.getDepartmentName());
//            if (null == deptId){
//                generalManageMapper.generalInsert(specimenRegisterDTO.getDepartmentName(), specimenRegisterDTO.getDepartmentName(),
//                        specimenRegisterDTO.getHospitalId(), null, 3, null);
//                deptId = specimenCheckMapper.getAppDeptIdForSpecimenCheckInsert(specimenRegisterDTO.getDepartmentName());
//            }
//            specimenRegisterDTO.setDepartmentId(deptId);
//        }
//        if(specimenRegisterDTO.getDoctorName()!=null){
//            Long doctorId = specimenCheckMapper.getDocIdForSpecimenCheckInsert(specimenRegisterDTO.getDoctorName(),
//                    specimenRegisterDTO.getHospitalId()!=null?specimenRegisterDTO.getHospitalId():213L);
//            if (doctorId == null){
//                doctorMapper.doctorAdd(specimenRegisterDTO.getDoctorName(),
//                        specimenRegisterDTO.getDoctorName(), null,specimenRegisterDTO.getHospitalId(), specimenRegisterDTO.getDepartmentId(), 212L, null);
//                doctorId = specimenCheckMapper.getDocIdForSpecimenCheckInsert(specimenRegisterDTO.getDoctorName(),
//                        specimenRegisterDTO.getHospitalId());
//            }
//            specimenRegisterDTO.setDoctorId(doctorId);
//        }
//        Boolean flag = inspectAppMapper.registerSpecimenEdit(specimenRegisterDTO);
//        if(!flag) {
//            return false;
//        }
//        return true;
//    }

//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public Boolean setSpecimenStatus(TableRequestDTO tableRequestDTO) throws Exception {
//        Boolean flag = inspectAppMapper.setSpecimenStatus(tableRequestDTO.getKey(), tableRequestDTO.getType());
//        if(!flag) {
//            return false;
//        }
//        return true;
//    }

//    @Override
//    public TableTCResponeDTO getSpecimenResult(TableRequestDTO tableRequestDTO) throws Exception {
//        // 查询结果表的条数
//        Long count = inspectAppMapper.count4Result(tableRequestDTO.getKey());
//        // 查询项目和结果  相关的数据
//        List<SpecimenResultDTO> list = inspectAppMapper.getSpecimenResult(tableRequestDTO.getStart(count),
//                tableRequestDTO.getPageSize(), tableRequestDTO.getKey());
//
//        for(int i=0;i<list.size();i++){
//            SpecimenResultDTO specimenResultDTO = list.get(i);
//            // 查询项目信息 封装到返回值里面
//            specimenResultDTO.setProjectDTO(printMapper.getProjectInfoById(specimenResultDTO.getProjectId()));
//
//            // 判断结果值是否是数字或者小数
//            if(AESUtil.isNumber(specimenResultDTO.getProjectValue())) {
//                // 参考值下限
//                Float min = specimenResultDTO.getProjectDTO().getExampleMin();
//                // 参考值上限
//                Float max = specimenResultDTO.getProjectDTO().getExampleMax();
//                // 结果值
//                Double result = Double.valueOf(specimenResultDTO.getProjectValue());
//
//                if (min != null && result < min) {
//                    // 小于下限
//                    specimenResultDTO.setResultTag(-1L);
//                } else if (max != null && result > max) {
//                    // 大于上限
//                    specimenResultDTO.setResultTag(1L);
//                } else {
//                    // 正常
//                    specimenResultDTO.setResultTag(0L);
//                }
//            }else {
//                // 结果值不是数字或者小数 比对结果值范围
//                if (specimenResultDTO.getExampleRange().equals(specimenResultDTO.getProjectValue())) {
//                    specimenResultDTO.setResultTag(0L);
//                } else {
//                    specimenResultDTO.setResultTag(1L);
//                }
//            }
//        }
//
//        TableTCResponeDTO result = new TableTCResponeDTO(list, new PaginationDTO(tableRequestDTO.getCurrent(),
//                tableRequestDTO.getPageSize(), count,tableRequestDTO.getCurrentPage()));
//
//        SpecimenRegisterDTO srdto = inspectAppMapper.getSpecimenRegisterByApplicationId(tableRequestDTO.getKey());
//
//        boolean savetag=false;
//        if(null != srdto.getProjectDocumentId()&& srdto.getSpecimenStatus()==2){
//            try {
//                List<SpecimenResultDTO> list1 = inspectAppMapper.getSpecimenAllResult(tableRequestDTO.getKey());
//                for (int i = 0; i < list1.size(); i++) {
//                    SpecimenResultDTO specimenResultDTO = list1.get(i);
//                    specimenResultDTO.setProjectDTO(printMapper.getProjectInfoById(specimenResultDTO.getProjectId()));
//                    if (AESUtil.isNumber(specimenResultDTO.getProjectValue())) {
//                        Float min = specimenResultDTO.getProjectDTO().getExampleMin();
//                        Float max = specimenResultDTO.getProjectDTO().getExampleMax();
//                        Double result1 = Double.valueOf(specimenResultDTO.getProjectValue());
//                        if (min != null && result1 < min) {
//                            specimenResultDTO.setResultTag(-1L);
//                        } else if (max != null && result1 > max) {
//                            specimenResultDTO.setResultTag(1L);
//                        } else {
//                            specimenResultDTO.setResultTag(0L);
//                        }
//                    } else {
//                        if (specimenResultDTO.getExampleRange().equals(specimenResultDTO.getProjectValue())) {
//                            specimenResultDTO.setResultTag(0L);
//                        } else {
//                            specimenResultDTO.setResultTag(1L);
//                        }
//                    }
//                }
//
//
//                if ("".equals(srdto.getTipInfo()) || null == srdto.getTipInfo()) {
//                    //获取相应的提示进行拼接
//                    List<ContentDTO> contentDTOS = contentMapper.getContentTipByPdid(srdto.getProjectDocumentId());
//                    result.setArray(contentDTOS);
//                    String explain = null;
//                    if (contentDTOS.size() > 0) {
//                        for (int i = 0; i < contentDTOS.size(); i++) {
//                            ContentDTO contentDTO = contentDTOS.get(i);
//                            String[] rule = contentDTO.getProjectIdMap().split(",");
//                            String compareString = compareResult(contentDTO.getRule(), contentDTO.getProjectIdMap(), list1);
////                        if(rule.length>0){
////                            for (int j = 0;j<rule.length;j++){
////                                String sunRule = rule[j];
////                                for(int k=0;k<list1.size();k++){
////                                    SpecimenResultDTO sun = list.get(k);
////                                    String pid = Long.toString(sun.getProjectId());
////                                    if(sunRule.contains(pid)){
////                                        if(sunRule.length()>pid.length()){
////                                            compareString=compareString+sunRule.substring(0,sunRule.indexOf(pid));
////                                        }else {
////                                            compareString=compareString+sun.getResultTag();
////                                        }
////                                    }
////                                }
////                            }
////                        }
//                            if (compareString.equals(contentDTO.getRule())) {//对比是否有规则产生
//                                if (contentDTO.getSplicing() > 0) {//对比是否为拼接
//                                    explain = explain + "，" + contentDTO.getContent();
//                                } else {
//                                    explain = contentDTO.getContent();
//                                }
//                            }
//                        }
//                        result.setTipInfo(explain);
//                        savetag = true;
//                    } else {
//                        result.setTipInfo(null);
//                    }
//
//                } else {
//                    result.setTipInfo(srdto.getTipInfo());
//                }
//
//                //获取相应的评论集合进行计算拼接
//                List<ContentDTO> contents = contentMapper.getContentByPdid(srdto.getProjectDocumentId());
//                List<String> content1 = new ArrayList<>(), content2 = new ArrayList<>(), content3 = new ArrayList<>(), content4 = new ArrayList<>();
//                if (contents.size() > 0) {
//                    for (int i = 0; i < contents.size(); i++) {
//                        ContentDTO contentDTO = contents.get(i);
//                        //进行规则比较
//                        String compareString = compareResult(contentDTO.getRule(), contentDTO.getProjectIdMap(), list1);
//
//                        if (compareString.equals(contentDTO.getRule())) {
//                            switch (contentDTO.getPage()) {
//                                case 1:
//                                    if (contentDTO.getSplicing() > 0) {
//                                        content1.add(contentDTO.getContent());
//                                    }
//                                    break;
//                                case 2:
//                                    if (contentDTO.getSplicing() > 0) {
//                                        content2.add(contentDTO.getContent());
//                                    }
//                                    break;
//                                case 3:
//                                    if (contentDTO.getSplicing() > 0) {
//                                        content3.add(contentDTO.getContent());
//                                    }
//                                    break;
//                                case 4:
//                                    if (contentDTO.getSplicing() > 0) {
//                                        content3.add(contentDTO.getContent());
//                                    }
//                                    break;
//                                default:
//                                    break;
//                            }
//                        }
//                    }
//                }
//                if ("".equals(srdto.getCommentFst()) || null == srdto.getCommentFst()) {
//                    if (content1.size() > 0) {
//                        result.setCommentFst(makeSentence(content1));
//                        savetag = true;
//                    } else {
//                        result.setCommentFst(null);
//                    }
//                } else {
//                    result.setCommentFst(srdto.getCommentFst());
//                }
//                if ("".equals(srdto.getCommentSec()) || null == srdto.getCommentSec()) {
//                    if (content2.size() > 0) {
//                        result.setCommentSec(makeSentence(content2));
//                        savetag = true;
//                    } else {
//                        result.setCommentSec(null);
//                    }
//                } else {
//                    result.setCommentSec(srdto.getCommentSec());
//                }
//                if ("".equals(srdto.getCommentThr()) || null == srdto.getCommentThr()) {
//                    if (content3.size() > 0) {
//                        result.setCommentThr(makeSentence(content3));
//                        savetag = true;
//                    } else {
//                        result.setCommentThr(null);
//                    }
//                } else {
//                    result.setCommentThr(srdto.getCommentThr());
//                }
//
//                if ("".equals(srdto.getCommentThr()) || null == srdto.getCommentThr()) {
//                    if (content3.size() > 0) {
//                        result.setCommentThr(makeSentence(content3));
//                        savetag = true;
//                    } else {
//                        result.setCommentThr(null);
//                    }
//                } else {
//                    result.setCommentThr(srdto.getCommentThr());
//                }
//
//                if ("".equals(srdto.getCommentFor()) || null == srdto.getCommentFor()) {
//                    if (content3.size() > 0) {
//                        result.setCommentFor(makeSentence(content4));
//                        savetag = true;
//                    } else {
//                        result.setCommentFor(null);
//                    }
//                } else {
//                    result.setCommentFor(srdto.getCommentFor());
//                }
//                if (savetag) {
//                    inspectAppMapper.updateTips(srdto.getSpecimenRegisterId(), result.getTipInfo(),
//                            result.getCommentFst(), result.getCommentSec(), result.getCommentThr(), result.getCommentFor());
//                }
//            }catch (Exception e){
//                e.printStackTrace();
//            }
//
//        }else {
//            result.setTipInfo(srdto.getTipInfo());
//            result.setCommentFst(srdto.getCommentFst());
//            result.setCommentSec(srdto.getCommentSec());
//            result.setCommentThr(srdto.getCommentThr());
//            result.setCommentFor(srdto.getCommentFor());
//        }
//        return result;
//    }

//    /**
//     * 用来进行规则匹配
//     * @param ruleString
//     * @param ruleMap
//     * @param list
//     * @return
//     */
//    private String compareResult(String ruleString,String ruleMap,List<SpecimenResultDTO> list){
//        String compareString="";
//        if (ruleString.length() > 0) {
//            if(!ruleString.contains("&")){
//                String[] rule = ruleMap.split(",");
//                String[] ruleText= ruleString.split(",");
//                for (int j = 0; j < rule.length; j++) {
//                    String sunRule = rule[j];
//                    for (int k = 0; k < list.size(); k++) {
//                        SpecimenResultDTO sun = list.get(k);
//                        String pid = Long.toString(sun.getProjectId());
//                        if (sunRule.contains(pid)) {
//                            if (AESUtil.isCharNumber(ruleText[j])) {
//                                long rulet = Long.parseLong(ruleText[j]);
//                                if (sun.getResultTag() == rulet) {
//                                    compareString = compareString + sun.getResultTag() + ",";
//                                }
//                            }else {
////                                String tag = sunRule.substring(0, sunRule.indexOf(pid));
//                                if("+".equals(ruleText[j]) && sun.getResultTag() != 0){
//                                    compareString = compareString + ruleText[j] + ",";
//                                }else if("#".equals(ruleText[j]) && sun.getResultTag()<=0){
//                                    compareString = compareString + ruleText[j] + ",";
//                                }else if("%".equals(ruleText[j]) && sun.getResultTag()>=0){
//                                    compareString = compareString + ruleText[j] + ",";
//                                }
//                            }
//                        }
//                    }
//                }
//                if(compareString.length()>1 && (compareString.lastIndexOf(",")==compareString.length()-1)){
//                    compareString = compareString.substring(0,compareString.lastIndexOf(","));
//                }
//            }else {
//                String[] rule = ruleMap.split(",");
//                String userString;
//                if(ruleString.indexOf("&")==0){
//                    userString = ruleString.substring(ruleString.indexOf("&")+1);
//                }else {
//                    userString = ruleString;
//                }
//                String[] ruleText= userString.split("&");
//                for (int j = 0; j < rule.length; j++) {
//                    String sunRule = rule[j];
//                    for (int k = 0; k < list.size(); k++) {
//                        SpecimenResultDTO sun = list.get(k);
//                        String pid = Long.toString(sun.getProjectId());
//                        if (sunRule.contains(pid)) {
//                            for(int p = 0;p<ruleText.length;p++){
//                                long cr = Long.parseLong(ruleText[p]);
//                                if(sun.getResultTag()==cr){
//                                    return ruleString;
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//
//        }else {
//            return "";
//        }
//        return compareString;
//    }


    /**
     * 将string拼接成句子
     * @param strings
     * @return
     */
    private String makeSentence(List<String> strings){
        String comment=""; int stringSize = strings.size();
        if(stringSize==0){
            return null;
        }
        for (int i= 0;i<stringSize;i++){
            String comment1=strings.get(i);
            if(i==0){
                if(stringSize>1){
                    comment=comment1;
                }else {
                    comment=comment1+"。";
                }
            }else if(i==stringSize-1){
                comment=comment+"，"+comment1+"。";
            }else {
                comment=comment+"，"+comment1;
            }
        }
        return comment;
    }



    @Override
    public TableResponseDTO getImage(Long applicationLinkId) throws Exception {
        List<ImageDTO> list = inspectAppMapper.getImage(applicationLinkId);
        return new TableResponseDTO(list);
    }

//    @Override
//    public TableResponseDTO getAllSpecimenId() throws Exception {
//        List<Long> list = inspectAppMapper.getAllSpecimenId();
//        return new TableResponseDTO(list);
//    }

//    @Override
//    public TableResponseDTO getAllPdfTemplate() throws Exception {
//        List<WordDTO> list = inspectAppMapper.getAllPdfTemplate();
//        return new TableResponseDTO(list);
//    }

//    @Override
//    public TableResponseDTO getAllSpecimenRequest(TableRequestDTO tableRequestDTO) throws Exception {
//        List<SpecimenRegisterDTO> array = inspectAppMapper.getAllUnregister(tableRequestDTO.getKey());
//        List<SpecimenRegisterDTO> list = inspectAppMapper.getAllSpecimenRequest(tableRequestDTO.getKey());
//        return new TableResponseDTO(list, array);
//    }

//    @Override
//    public Boolean checkSpecimen(SpecimenRegisterDTO specimenRegisterDTO) throws Exception {
//        Boolean flag = inspectAppMapper.checkSpecimen(specimenRegisterDTO.getSpecimenRegisterId(),
//                specimenRegisterDTO.getConfirmManId());
//        return flag;
//    }

//    @Override
//    public Boolean resultEdit(SpecimenResultDTO specimenResultDTO) throws  Exception {
//        Boolean flag = inspectAppMapper.resultEdit(specimenResultDTO.getSpecimenResultId(), specimenResultDTO.getProjectValue());
//        return flag;
//    }

//    /**
//     * 单个状态修改
//     * @param specimenRegisterDTO
//     * @return
//     * @throws Exception
//     */
//    @Override
//    public Boolean specimenStatusEdit(SpecimenRegisterDTO specimenRegisterDTO) throws Exception {
//        Boolean flag;
//        if(specimenRegisterDTO.getSpecimenStatus() < 2){
//            flag = inspectAppMapper.setSpecimenStatusClear(specimenRegisterDTO.getSpecimenRegisterId(), specimenRegisterDTO.getSpecimenStatus());
//        }else {
//            flag = inspectAppMapper.setSpecimenStatus(specimenRegisterDTO.getSpecimenRegisterId(), specimenRegisterDTO.getSpecimenStatus());
//        }
//
//        Boolean result = flag;
//        if(specimenRegisterDTO.getSpecimenStatus() < 2) {
//            Boolean flag1 = inspectAppMapper.clearResult(specimenRegisterDTO.getSpecimenExtraId());
//            Boolean flag2 = inspectAppMapper.clearImage(specimenRegisterDTO.getSpecimenExtraId());
//            result = (flag && flag1 && flag2);
//        }
//        return result;
//    }

//    // 结果上传
//    @Override
//    public void specimenUpload(SpecimenRegisterDTO specimenRegisterDTO) throws Exception {
//        ObjectDTO objectDTO = objectMapper.getHosptalById(specimenRegisterDTO.getHospitalId());
//        specimenRegisterDTO.setUploadTag(objectDTO.getUploadTag());
//        Long result = hospitalUploadMapper.checkHasTestData(specimenRegisterDTO.getPlaceholderCode(),specimenRegisterDTO.getHospitalId());
//        if(result>0){
////            System.out.println("还有正在检测的项目哟");
//            return;
//        }
//        //判断是否需要有上传的标志，若没有上传标志则不进行上传
//        if ( specimenRegisterDTO.getUploadTag()!= null && specimenRegisterDTO.getUploadTag() == 1){
//            HospitalUploadGetDTO hospitalUploadGetDTO = new HospitalUploadGetDTO();
//            hospitalUploadGetDTO.setPlaceholderCode(specimenRegisterDTO.getPlaceholderCode());
//            hospitalUploadGetDTO.setHospitalId(specimenRegisterDTO.getHospitalId());
////            System.out.println("现在已经可以发送拉");
//            TableResponseDTO tableResponseDTO = hospitalUploadService.handOnSpecimen(hospitalUploadGetDTO,objectDTO.getUppdf());
//        }else {
//
//        }
//    }

//    @Override
//    public Long checkDailyCode(String dailyCode, Long officeId, Long applicationLinkId) throws Exception {
//        String receiveTime = inspectAppMapper.getReceiveTime(applicationLinkId);
//        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//        Date receiveDate = format.parse(receiveTime);
//        Calendar c = Calendar.getInstance();
//        c.setTime(receiveDate);
//        c.add(Calendar.DAY_OF_MONTH, 1);
//        // 获取核收时间的dailyCodes
//        List<String> dailyCodes = inspectAppMapper.getDailyCodeList(officeId, receiveDate, c.getTime());
//        // 返回已完成状态的个数
//        return dailyCodes.contains(dailyCode) ? -1L: 1L;
//    }

//    @Override
//    public DailyCodeDTO getDailyCodeListWithCompleted(String dailyCode, Long officeId, Long applicationLinkId) throws Exception {
//        // 收到时间
//        String receiveTime = inspectAppMapper.getReceiveTime(applicationLinkId);
//        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//        Date receiveDate = format.parse(receiveTime);
//        Calendar c = Calendar.getInstance();
//        c.setTime(receiveDate);
//        c.add(Calendar.DAY_OF_MONTH, 1);
//        // 获取核收时间的dailyCodes
//        DailyCodeDTO res = new DailyCodeDTO();
//        res.setCompletedCount(inspectAppMapper.getDailyCodeListWithCompleted(officeId, receiveDate, c.getTime(), dailyCode));
//        res.setTotal(inspectAppMapper.getDailyCodeCount(officeId, receiveDate, c.getTime(), dailyCode));
//        res.setDailyCode(dailyCode);
//        // 返回已完成状态的个数
//        return res;
//    }

//    @Override
//    public Long setDailyCode(String dailyCode, Long applicationLinkId) {
//        return inspectAppMapper.setDailyCode(applicationLinkId, dailyCode);
//    }

//    @Override
//    public List<SpecimenRegisterDTO> getSpecimenRegisterDTOById(List<Long> longs) {
//        List<SpecimenRegisterDTO> list =new ArrayList<>();
//        if(longs.size()>0){
//            for(int i =0;i<longs.size();i++){
//                list.add(inspectAppMapper.getSpecimenRequestByApplicationId(longs.get(i)));
//            }
//        }
//        return list;
//    }

//    @Override
//    public TableResponseDTO deleteRequest(TableRequestDTO tableRequestDTO){
//        TableResponseDTO responseDTO = new TableResponseDTO();
//        try {
//            if(tableRequestDTO.getArray().size()>0){
//                for(int i = 0 ; i<tableRequestDTO.getArray().size();i++){
//                    Long id = tableRequestDTO.getArray().get(i);
//                    inspectAppMapper.removeRequest(id);
//                    inspectAppMapper.removeRequestId(id);
//                }
//            }
//            responseDTO.setResponseCode(SystemConstant.OP_SUCCESS_LONG);
//            responseDTO.setOpResult(SystemConstant.OP_SUCCESS_OBJ);
//        }catch (Exception e){
//            responseDTO.setResponseCode(SystemConstant.OP_FAILURE_LONG);
//            responseDTO.setOpResult(SystemConstant.OP_FAILURE_OBJ);
//        }
//
//        return responseDTO;
//    }

//    /**
//     * 批量状态修改
//     * @param id
//     * @param status
//     * @return
//     * @throws Exception
//     */
//    @Override
//    public Boolean  specimenStatusUpdate( Long id, Integer status)throws Exception {
//        Boolean flag = inspectAppMapper.setSpecimenStatusByExtraId(id, status);
//        Boolean result = flag;
//        if(status < 2) {
//            Boolean flag1 = inspectAppMapper.clearResult(id);
//            Boolean flag2 = inspectAppMapper.clearImage(id);
//            result = (flag && flag1 && flag2);
//        }
//        return result;
//    }

}
